package com.xymtop.api.controller;

import com.xymtop.api.config.ServerStatus;
import com.xymtop.api.entity.PTeacher;
import com.xymtop.api.service.PTeacherService;
import com.xymtop.api.utils.JsonResoult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName : PTeacherController
 * @Description : 教师信息控制器
 * @Author : 肖叶茂
 * @Date: 2022/12/1  16:42
 */
@RestController
@RequestMapping("pteacher")
public class PTeacherController   {
    @Autowired
    private PTeacherService pTeacherService;

    @RequestMapping("add")
    public JsonResoult<String> add(@RequestParam("projectid") String projectid, @RequestParam("name") String name, @RequestParam("jobtitle") String jobtitle,
                                   @RequestParam("information") String information,@RequestParam("rank") String rank) {

        PTeacher pTeacher = new PTeacher();
        pTeacher.setProjectid(projectid);
        pTeacher.setName(name);
        pTeacher.setInformation(information);
        pTeacher.setJobtitle(jobtitle);
        pTeacher.setRank(rank);

        if(pTeacherService.add(pTeacher)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }
    }


    @RequestMapping("delete")
    public JsonResoult<String> delete(@RequestParam("projectid") String projectid, @RequestParam("name") String name) {
        if(pTeacherService.delete(projectid, name)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }
    }


    @RequestMapping("changeRank")
    public JsonResoult<String> changeRank(@RequestParam("projectid") String projectid,@RequestParam("name") String name,
                                          @RequestParam("rank") String rank) {
        if(pTeacherService.changeRank(projectid, name, rank)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }
    }



    @RequestMapping("getList")
    public JsonResoult<List<PTeacher>> getList(@RequestParam("projectid") String projectid) {
        return new JsonResoult<>(200,"",pTeacherService.getList(projectid));
    }
}
